home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE6 / PD / PDF / DrawFile / h / GuiDrawFile < prev    next >
Text File  |  2003-02-14  |  4KB  |  133 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //   Copyright (c) 2002, Colin Granville
  4. //
  5. //   All rights reserved.
  6. //
  7. //   Redistribution and use in source and binary forms, with or
  8. //   without modification, are permitted provided that the following 
  9. //   conditions are met:
  10. //
  11. //      * Redistributions of source code must retain the above copyright 
  12. //        notice, this list of conditions and the following disclaimer.
  13. //
  14. //      * Redistributions in binary form must reproduce the above 
  15. //        copyright notice, this list of conditions and the following 
  16. //        disclaimer in the documentation and/or other materials 
  17. //        provided with the distribution.
  18. //
  19. //      * The name Colin Granville may not be used to endorse or promote 
  20. //        products derived from this software without specific prior 
  21. //        written permission.
  22. //
  23. //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  24. //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  25. //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  26. //   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  27. //   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
  28. //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  29. //   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30. //   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  31. //   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  32. //   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  33. //   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
  34. //   OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //--------------------------------------------------------------------------
  37.  
  38. #ifndef GuiDrawFile_h
  39. #define GuiDrawFile_h
  40.  
  41. #include "GuiBBox.h"
  42. #include "swis.h"
  43. #include "stl:string.h"
  44. #include <stdlib.h>
  45. #include "flex_c.h"
  46.  
  47. class GuiDrawFileObject
  48. {
  49.   public:
  50.     int    typeId;
  51.     size_t size;
  52. };
  53.  
  54. class GuiDrawFileGraphicsObject : public GuiDrawFileObject
  55.   public:
  56.     GuiBBox bounds;
  57. };
  58.  
  59. class GuiTransform
  60. {
  61.   public:
  62.     GuiTransform() {m0=m3=(1<<16);m1=m2=m4=m5=0;}
  63.     int m0,m1,m2,m3,m4,m5;
  64. };
  65.  
  66. class GuiDrawFile
  67. {
  68.   private:
  69.     bool         extend(size_t);
  70.     FlexChar     data;
  71.     enum {FILE_FAILED=1,OBJECT_FAILED=2};
  72.   public:
  73.     GuiDrawFile(const char* programName);
  74.     virtual ~GuiDrawFile();
  75.     void             reopen();
  76.     _kernel_oserror* save(const char* filename);
  77.     _kernel_oserror* render(const GuiTransform* trans=0, const GuiBBox* clip=0, bool blendFont=1) const;
  78.     _kernel_oserror* getBBox(GuiBBox&,const GuiTransform* trans=0) const;
  79.     _kernel_oserror* declareFonts(bool dont_download=0) const;  
  80.  
  81.     void  put(size_t i)
  82.     {
  83.       if (size<=capacity-sizeof(size_t) || extend(sizeof(size_t)))
  84.       {
  85.         ((size_t&)data.at(size))=i;
  86.         size+=sizeof(size_t);
  87.       }
  88.     }
  89.     void  put(int i)               {put((size_t)i);}
  90.     void  put(char c)
  91.     {
  92.        if (size<capacity || extend(sizeof(char))) data[size++]=c;
  93.     }
  94.  
  95.     char*        getPtr(int pos)              {return &data.at(pos);}
  96.     const char*  getPtr(int pos) const        {return &data.at(pos);}
  97.  
  98.     enum   {npos=-1}; //invalid size_t
  99.     size_t getSize() const               {return size;}
  100.  
  101.     size_t startObject(size_t size); //returns position of object
  102.     void   endObject();
  103.     void   endCurrentObject();
  104.  
  105.     void  addBBox(const GuiBBox& bbox)  {
  106.                                           if (bbox.xmin<bounds.xmin) bounds.xmin=bbox.xmin;
  107.                                           if (bbox.xmax>bounds.xmax) bounds.xmax=bbox.xmax;
  108.                                           if (bbox.ymin<bounds.ymin) bounds.ymin=bbox.ymin;
  109.                                           if (bbox.ymax>bounds.ymax) bounds.ymax=bbox.ymax;
  110.                                         }
  111.     void setBBox(const GuiBBox& bbox)   {bounds=bbox;}
  112.     
  113.     void  align()                       {size=((size+3) &~3);}
  114.     bool  hasFailed()                   {return failed;}
  115.  
  116.     void  ensureMem(unsigned int size);
  117.  
  118.   private:
  119.     size_t   size;
  120.     size_t   capacity;
  121.     GuiBBox  bounds;
  122.     string   programName;
  123.     int      currentObject;
  124.     int      failed;
  125.  
  126.     void         setBBox(); 
  127.     void         setBBox() const; 
  128.     size_t       allocate(size_t size);
  129. };
  130.  
  131. #endif
  132.